# Windows PowerShell 构建部署脚本
# 月经周期管理应用一键构建部署脚本

Write-Host "=== 月经周期管理应用构建部署脚本 ===" -ForegroundColor Green
Write-Host "开始构建应用..." -ForegroundColor Yellow

# 检查当前目录
if (-not (Test-Path ".\entry")) {
    Write-Host "错误：请在项目根目录运行此脚本" -ForegroundColor Red
    exit 1
}

# 清理构建缓存
Write-Host "清理构建缓存..." -ForegroundColor Cyan
.\hvigorw clean

if ($LASTEXITCODE -ne 0) {
    Write-Host "清理失败，继续构建..." -ForegroundColor Yellow
}

# 安装依赖
Write-Host "安装依赖..." -ForegroundColor Cyan
.\hvigorw ohosDependencies

if ($LASTEXITCODE -ne 0) {
    Write-Host "依赖安装失败，尝试继续构建..." -ForegroundColor Yellow
}

# 编译应用
Write-Host "编译应用..." -ForegroundColor Cyan
.\hvigorw assembleApp

if ($LASTEXITCODE -ne 0) {
    Write-Host "编译失败，请检查错误信息" -ForegroundColor Red
    exit 1
}

Write-Host "编译成功！" -ForegroundColor Green

# 部署到设备
Write-Host "部署应用到设备..." -ForegroundColor Cyan
$devices = hdc_std list targets
if ($devices -match "device") {
    Write-Host "找到设备，开始部署..." -ForegroundColor Green
    hdc_std install -r .\entry\build\default\outputs\default\entry-default-unsigned.hap
    if ($LASTEXITCODE -eq 0) {
        Write-Host "部署成功！" -ForegroundColor Green
        Write-Host "启动应用..." -ForegroundColor Cyan
        hdc_std shell aa start -a EntryAbility -b com.example.myapplication
        Write-Host "应用已启动" -ForegroundColor Green
    } else {
        Write-Host "部署失败，请检查设备连接" -ForegroundColor Red
    }
} else {
    Write-Host "未找到可用设备，请连接设备或启动模拟器" -ForegroundColor Yellow
}

Write-Host "=== 构建部署完成 ===" -ForegroundColor Green
Write-Host "按任意键退出..." -ForegroundColor Gray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")